{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "68e573aa",
   "metadata": {
    "scrolled": true
   },
   "source": [
    "# 本周主要内容：图像识别（人脸识别）\n",
    "  \n",
    "## 23春_API_人工智能与机器学习_week04  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "39936464",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "## 1. 人脸识别概念和基础\n",
    "## 2. 人脸识别应用\n",
    "## 3. 人脸识别实践-face++\n",
    "* 1.人脸检测\n",
    "* 2.人脸比对+人脸搜索\n",
    "**1.人脸集合创建\n",
    "**2.人脸"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18755efc",
   "metadata": {},
   "source": [
    "# 人脸识别概念和基础"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c5a0b18",
   "metadata": {},
   "source": [
    "https://gitee.com/link?target=https%3A%2F%2Fzhuanlan.zhihu.com%2Fp%2F36262110"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d0869692",
   "metadata": {},
   "outputs": [
    {
     "ename": "FileNotFoundError",
     "evalue": "[Errno 2] No such file or directory: 'gao_01.jpg'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mFileNotFoundError\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36m<cell line: 13>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     10\u001b[0m request_url \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://api-cn.faceplusplus.com/facepp/v3/detect\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m     11\u001b[0m \u001b[38;5;66;03m# 二进制方式打开图片文件\u001b[39;00m\n\u001b[0;32m     12\u001b[0m \u001b[38;5;66;03m# 1.图片文件准备\u001b[39;00m\n\u001b[1;32m---> 13\u001b[0m f \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mgao_01.jpg\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mrb\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m     14\u001b[0m img \u001b[38;5;241m=\u001b[39m base64\u001b[38;5;241m.\u001b[39mb64encode(f\u001b[38;5;241m.\u001b[39mread())\n\u001b[0;32m     16\u001b[0m \u001b[38;5;66;03m# 2. 酬载准备\u001b[39;00m\n",
      "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'gao_01.jpg'"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸对比\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('gao_01.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2. 酬载准备\n",
    "payload = {\n",
    "    'api_key':'zm08EBCxK4rS7R35ks2u6OzAUh6mcfwy',\n",
    "    'api_secret':'esQp7sClEenWKMiw4Rt1x1PXX_ymgnFC',\n",
    "    'image_base64':img_gao01,\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,emotion,blur,beauty'\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data = payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88c64f81",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "55969c19",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
